<?php
namespace PingNa\Controller;
use Common\Lib\Category;
use Think\Controller;
class ArticleController extends HomeCommonController {
    private $newCatalogId = 135;//新闻中心栏目ID
    public function index(){
        $postId = I('postId');
        $postInfo = M('article')->find($postId);
        $lastProductId = M('article')->where('publishtime > '.$postInfo['publishtime'].' and cid ='.$postInfo['cid'].' and status=0')->limit(1)->field('id,title')->order('publishtime asc')->select()[0];
        $nextProductId = M('article')->where('publishtime < '.$postInfo['publishtime'].' and cid ='.$postInfo['cid'].' and status=0')->limit(1)->field('id,title')->order('publishtime desc')->select()[0];
        $this->assign('postInfo',$postInfo);
        $this->assign('nextProductId',$nextProductId);
        $this->assign('lastProductId',$lastProductId);

        $catalogInfo = M('category')->find($this->newCatalogId);
        $this->assign('avtiveId',$catalogInfo['id']);
        $this->assign('headInfo',$catalogInfo);
        $footHtml = $this->getTemplatePage('foot.html');
        $head_navlist = $this->getTemplatePage('head_navlist.html');
        $this->assign('footHtml',$footHtml);
        $this->assign('head_navlist',$head_navlist);


        $activeCatalogId = $postInfo['cid'];
        $this->assign('activeCatalogId',$activeCatalogId);
        $this->display();
        self::addView($postId,$postInfo['click']+1);
    }

    private function addView($id,$num){
        $m = M('article');
        $m->click = $num;
        $m->where(['id'=>$id])->save();
    }
}?>